package com.renge.statisticsservice.controller;


import com.renge.commonutils.R;
import com.renge.exception.GuliException;
import com.renge.statisticsservice.entity.vo.AnalysisVo;
import com.renge.statisticsservice.service.StatisticsDailyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-07-02
 */
@RestController
@Api(description="分析管理")
@CrossOrigin
@RequestMapping("/statisticsservice/statistics-daily")
public class StatisticsDailyController {
    @Autowired
    private StatisticsDailyService service;

    @ApiOperation(value = "添加分析信息到分析表")
    @GetMapping("/coderegister/{day}")
    public R addStatisticsToTable(@ApiParam(name = "day", value = "日期格式：2021-06-29", required = true)
                                      @PathVariable("day") String day){
        service.addStatisticsToTable(day);
        return R.ok();
    }
    @ApiOperation(value = "分析信息查询返回")
    @PostMapping("/coderegister/analysis")
    public R checkAnalysisToTable(@ApiParam(name = "AnalysisVo", value = "分析查询封装类", required = true)
                                  @RequestBody AnalysisVo analysisVo){
        Map<String,Object>analysisMap=service.checkAnalysisToTable(analysisVo);
        if(StringUtils.isEmpty(analysisMap)){
            throw new GuliException(20001,"查询失败");
        }
        return R.ok().data("analysisMap",analysisMap);
    }

}

